package gbench.sandbox.plot.geom;

import static gbench.common.matlib.MatlibCanvas.meshgrid;
import static gbench.common.matlib.MatlibCanvas.rgbNVec;
import static gbench.common.matlib.MatlibCanvas.Range.P2;
import static gbench.common.matlib.MatlibCanvas.Range.rG;
import static java.lang.Math.PI;
import static java.lang.Math.cos;
import static java.lang.Math.sin;

import gbench.common.matlib.MatlibCanvas;

/**
 * 采样网格的演示
 * @author gbench
 *
 */
public class JunitMeshgrid {
    
    /**
     * 绘制采样网格
     */
    public static void plot() {
        final var size = 1000; // 数据尺寸
        final var matlib = new MatlibCanvas(size); // matlib 绘图结构
        matlib.plot(size, size / 2, pen -> {
            meshgrid(1000, 500).forEach(nvec -> pen.drawPoint(nvec.concat(rgbNVec("0000CC")))); // 绘制一个蓝色背景
            rG(0, 1000, 100).forEach(i -> pen.setColor("#C0C0C0").drawLineX(x -> i).drawLineY(y -> i)); // 绘制网格
            pen.setColor("CC0066").drawPoints(P2(-PI, PI, 1000).map(matlib.fx(x -> sin(x))).map(e -> e.affine(100, 100, 500, 250))); // 正弦线
            pen.setColor("990099").drawPoints(P2(-PI, PI, 1000).map(matlib.fx(x -> cos(x))).map(e -> e.affine(100, 100, 500, 250))); // 余弦线
            pen.setColor("#ffff00"); // 设置黄色绘图色
            P2(-PI, PI, 1000).mapDouble(matlib::rhoTheta).map(e -> e.affine(100, 200, 500, 250)).forEach(pen::drawPoint); // 拉伸单位元
            pen.setColor("#ff0000"); // 设置红色绘图色
            meshgrid(P2(0, 100, 1000), P2(-PI, PI, 1000)).map(matlib.rhotheta2_affine(1, 1, 200, 250)).forEach(pen::drawPoint); // 绘制实心圆
        });
    }

    public static void main(String args[]) {
        plot();
    }
}
